package com.cn.aam.checaiduo.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.TextView;


public class MyTextViewUtils {
    //获取编辑框的内容
    public static String getContent(TextView textView) {
        if (textView != null) {
            return textView.getText().toString().trim();
        }
        return null;
    }


    /**
     * 顶部画drawable
     */
    public static void setTopDrwable(Context context, TextView mTextView, int recourse) {
        Drawable drawable = context.getResources().getDrawable(recourse);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        mTextView.setCompoundDrawables(null, drawable, null, null);//画在左边边
    }

    /**
     * 左边画drawable
     */
    public static void setLeftDrwable(Context context, TextView mTextView, int recourse) {
        Drawable drawable = context.getResources().getDrawable(recourse);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        mTextView.setCompoundDrawables(drawable, null, null, null);//画在左边边
    }


    /**
     * 右边边画drawable
     */
    public static void setRightDrwable(Context context, TextView mTextView, int recourse) {
        Drawable drawable = context.getResources().getDrawable(recourse);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        mTextView.setCompoundDrawables(null, null, drawable, null);//画在左边边
    }

    /**
     * 清除原有的drawable
     *
     * @param mTextView
     */
    public static void clearDrawable(TextView mTextView) {
        mTextView.setCompoundDrawables(null, null, null, null);//画在左边边
    }

    //显示阴影
    public static void showAllShadow(TextView... texteViews) {
        for (TextView mTextView : texteViews) {
            mTextView.setShadowLayer(20, 0, 10, android.R.color.black);
        }
    }

    /**
     * 改变颜色
     */
    public static void changeColor(int color, TextView... textViews) {
        for (TextView mTextView : textViews) {
            mTextView.setTextColor(color);
        }
    }

    /**
     * 针对TextView显示中文中出现的排版错乱问题，通过调用此方法得以解决
     *
     * @param str
     * @return 返回全部为全角字符的字符串
     */
    public static String toDBC(String str) {
        char[] c = str.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 12288) {
                c[i] = (char) 32;
                continue;
            }
            if (c[i] > 65280 && c[i] < 65375) {
                c[i] = (char) (c[i] - 65248);
            }

        }
        return new String(c);
    }

}
